package com.lvyq.myplayer.ui.activity.singer

import android.content.Intent
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.adapter.IndexDailyPlayListAdapter
import com.lvyq.myplayer.base.BaseActivity
import com.lvyq.myplayer.model.singer.SingerAlbumData
import com.lvyq.myplayer.model.singer.SingerSongBean
import com.lvyq.myplayer.parcelable.SongInfoData
import com.lvyq.myplayer.ui.activity.AudioPlayerActivity
import com.lvyq.myplayer.util.NetworkUtils
import com.lvyq.myplayer.util.URLProviderUtils
import com.squareup.picasso.Picasso

/**
 * 文件描述：歌手专辑
 * 作者：lvyq
 * 创建时间：2025-04-29
 * 修改时间：2025-04-29
 */
class SingerAlbumActivity: BaseActivity() {



    override fun getLayoutId(): Int {
        return R.layout.activity_singer_album
    }

    override fun initData() {
        var data: SingerAlbumData? = intent.getParcelableExtra("data")

        var recyclerView = findViewById<RecyclerView>(R.id.dailyLst)
        //设置处置列表
        recyclerView.layoutManager=LinearLayoutManager(this)

        var bannerImg = findViewById<ImageView>(R.id.bannerImg)
        var content =findViewById<TextView>(R.id.content)
        var albumName =findViewById<TextView>(R.id.albumName)
        val url = URLProviderUtils.getSingerSongPage100BySongId(
            data?.id.toString(),data?.singerId)
        NetworkUtils.get(
            url = url,
            responseClass = SingerSongBean::class.java,
            successCallback = { pageData ->
                val dailyAdapter = IndexDailyPlayListAdapter(this,pageData.rows)
                recyclerView.adapter=dailyAdapter
                dailyAdapter.setOnItemClickListener(object :IndexDailyPlayListAdapter.OnItemClickListener{
                    override fun onItemClick(data: SongInfoData, position: Int) {
                        //跳转播放页面
                        var intent = Intent(this@SingerAlbumActivity, AudioPlayerActivity::class.java)
                        intent.putExtra("position",position)
                        intent.putExtra("data",data)
                        intent.putParcelableArrayListExtra("songLst",pageData.rows)
                        startActivity(intent)
                    }

                })

            },
            errorCallback = { errorMsg ->
                Log.e("SingerSongPagerFragment", "加载失败：$errorMsg")
            }
        )
        Picasso.with(this).load(data?.bgImg).into(bannerImg)
        content.text=data?.albumName
        albumName.text=data?.albumName
    }


}

